import ApplicationContext from "./ApplicationContext.js"
import  Resource from "./decorator/Resource.js"
import Synchro from "./control/Synchro.js"
const inBrowser = typeof window !== 'undefined'
import DefaultLoad from "./load/DefaultLoad.js"
export default class QGuanRunApplication{

    constructor(parmList,resolve){
        // this.applicationContext =ApplicationContext.getInstance();
        console.log("启动 轻管")
        let context=  ApplicationContext.getInstance();
        context.saveBend('resource',Resource) ;
        context.saveBend('save',save) ;
        context.saveBend('defaultLoad',DefaultLoad) ;

        context.saveBend('synchro',Synchro) ;
        if(inBrowser){
            window.applicationContext=context
            window.qguan=find;
        }else {
            global.applicationContext =context
            global.qguan=find
        }

        applicationContext.inBrowser=inBrowser;

        console.log("启动成功")

    }

}
function save(a,b,c,d){
    applicationContext.saveBend(a,b,c,d);
}

function find(a,b,c,d){
    if(arguments.length==1||arguments.length==4){
        return applicationContext.find(a,b,c,d);
    }
    debugger
    let className="";
    let jsrName="";
    let pathName=""
   if(a==0){ //  a==0 表示从自己包里加载
       //如果 等于空使用 默认加载器加载
       //console.log((new Error()).stack.split("\n")[2].trim().split(" ")[1])  //获取调用栈的信息
       let coller=  (new Error()).stack.split("\n")[2].trim().split(" ")[1] ;

       let collers= coller.split("_"); //截取报名
       jsrName=collers[1]
   }else {
       jsrName=a
   }

    if(!c){
        className=c;
        pathName=b;
    }else if(b){
        className =b
    }
    return  applicationContext.find(jsrName,pathName,className,'defaultLoad');


}
